<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="太阳膜" prop="solarFilm">
        <el-input
          v-model="queryParams.solarFilm"
          placeholder="请输入太阳膜"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="太阳膜自定义尺寸" prop="solarFilmSize">
        <el-input
          v-model="queryParams.solarFilmSize"
          placeholder="请输入太阳膜自定义尺寸"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="改色膜" prop="colorChangeFilm">
        <el-input
          v-model="queryParams.colorChangeFilm"
          placeholder="请输入改色膜"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="改色膜自定义尺寸" prop="colorChangeFilmSize">
        <el-input
          v-model="queryParams.colorChangeFilmSize"
          placeholder="请输入改色膜自定义尺寸"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="漆面膜" prop="lacquerFilm">
        <el-input
          v-model="queryParams.lacquerFilm"
          placeholder="请输入漆面膜"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="漆面膜自定义尺寸" prop="lacquerFilmSize">
        <el-input
          v-model="queryParams.lacquerFilmSize"
          placeholder="请输入漆面膜自定义尺寸"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主体颜色" prop="color">
        <el-input
          v-model="queryParams.color"
          placeholder="请输入主体颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主体颜色自定义" prop="colorCustomize">
        <el-input
          v-model="queryParams.colorCustomize"
          placeholder="请输入主体颜色自定义"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主体颜色占比" prop="colorProportion">
        <el-input
          v-model="queryParams.colorProportion"
          placeholder="请输入主体颜色占比"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主体颜色占比自定义" prop="colorProportionCustomize">
        <el-input
          v-model="queryParams.colorProportionCustomize"
          placeholder="请输入主体颜色占比自定义"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="风格" prop="style">
        <el-input
          v-model="queryParams.style"
          placeholder="请输入风格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="风格自定义" prop="styleCustomize">
        <el-input
          v-model="queryParams.styleCustomize"
          placeholder="请输入风格自定义"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="包装体现" prop="packagingReflects">
        <el-input
          v-model="queryParams.packagingReflects"
          placeholder="请输入包装体现"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="特殊工艺" prop="specialProcess">
        <el-input
          v-model="queryParams.specialProcess"
          placeholder="请输入特殊工艺"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产工艺" prop="productionProcess">
        <el-input
          v-model="queryParams.productionProcess"
          placeholder="请输入生产工艺"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="太阳膜" align="center" prop="solarFilm" />
      <el-table-column label="太阳膜自定义尺寸" align="center" prop="solarFilmSize" />
      <el-table-column label="改色膜" align="center" prop="colorChangeFilm" />
      <el-table-column label="改色膜自定义尺寸" align="center" prop="colorChangeFilmSize" />
      <el-table-column label="漆面膜" align="center" prop="lacquerFilm" />
      <el-table-column label="漆面膜自定义尺寸" align="center" prop="lacquerFilmSize" />
      <el-table-column label="盒型" align="center" prop="boxType" />
      <el-table-column label="主体颜色" align="center" prop="color" />
      <el-table-column label="主体颜色自定义" align="center" prop="colorCustomize" />
      <el-table-column label="主体颜色占比" align="center" prop="colorProportion" />
      <el-table-column label="主体颜色占比自定义" align="center" prop="colorProportionCustomize" />
      <el-table-column label="风格" align="center" prop="style" />
      <el-table-column label="风格自定义" align="center" prop="styleCustomize" />
      <el-table-column label="包装体现" align="center" prop="packagingReflects" />
      <el-table-column label="特殊工艺" align="center" prop="specialProcess" />
      <el-table-column label="生产工艺" align="center" prop="productionProcess" />
      <el-table-column label="状态 0 正常    1 停用" align="center" prop="status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="太阳膜" prop="solarFilm">
          <el-input v-model="form.solarFilm" placeholder="请输入太阳膜" />
        </el-form-item>
        <el-form-item label="太阳膜自定义尺寸" prop="solarFilmSize">
          <el-input v-model="form.solarFilmSize" placeholder="请输入太阳膜自定义尺寸" />
        </el-form-item>
        <el-form-item label="改色膜" prop="colorChangeFilm">
          <el-input v-model="form.colorChangeFilm" placeholder="请输入改色膜" />
        </el-form-item>
        <el-form-item label="改色膜自定义尺寸" prop="colorChangeFilmSize">
          <el-input v-model="form.colorChangeFilmSize" placeholder="请输入改色膜自定义尺寸" />
        </el-form-item>
        <el-form-item label="漆面膜" prop="lacquerFilm">
          <el-input v-model="form.lacquerFilm" placeholder="请输入漆面膜" />
        </el-form-item>
        <el-form-item label="漆面膜自定义尺寸" prop="lacquerFilmSize">
          <el-input v-model="form.lacquerFilmSize" placeholder="请输入漆面膜自定义尺寸" />
        </el-form-item>
        <el-form-item label="主体颜色" prop="color">
          <el-input v-model="form.color" placeholder="请输入主体颜色" />
        </el-form-item>
        <el-form-item label="主体颜色自定义" prop="colorCustomize">
          <el-input v-model="form.colorCustomize" placeholder="请输入主体颜色自定义" />
        </el-form-item>
        <el-form-item label="主体颜色占比" prop="colorProportion">
          <el-input v-model="form.colorProportion" placeholder="请输入主体颜色占比" />
        </el-form-item>
        <el-form-item label="主体颜色占比自定义" prop="colorProportionCustomize">
          <el-input v-model="form.colorProportionCustomize" placeholder="请输入主体颜色占比自定义" />
        </el-form-item>
        <el-form-item label="风格" prop="style">
          <el-input v-model="form.style" placeholder="请输入风格" />
        </el-form-item>
        <el-form-item label="风格自定义" prop="styleCustomize">
          <el-input v-model="form.styleCustomize" placeholder="请输入风格自定义" />
        </el-form-item>
        <el-form-item label="包装体现" prop="packagingReflects">
          <el-input v-model="form.packagingReflects" placeholder="请输入包装体现" />
        </el-form-item>
        <el-form-item label="特殊工艺" prop="specialProcess">
          <el-input v-model="form.specialProcess" placeholder="请输入特殊工艺" />
        </el-form-item>
        <el-form-item label="生产工艺" prop="productionProcess">
          <el-input v-model="form.productionProcess" placeholder="请输入生产工艺" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/system/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        sex: null,
        age: null,
        solarFilm: null,
        solarFilmSize: null,
        colorChangeFilm: null,
        colorChangeFilmSize: null,
        lacquerFilm: null,
        lacquerFilmSize: null,
        boxType: null,
        color: null,
        colorCustomize: null,
        colorProportion: null,
        colorProportionCustomize: null,
        style: null,
        styleCustomize: null,
        packagingReflects: null,
        specialProcess: null,
        productionProcess: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userName: null,
        sex: null,
        age: null,
        solarFilm: null,
        solarFilmSize: null,
        colorChangeFilm: null,
        colorChangeFilmSize: null,
        lacquerFilm: null,
        lacquerFilmSize: null,
        boxType: null,
        color: null,
        colorCustomize: null,
        colorProportion: null,
        colorProportionCustomize: null,
        style: null,
        styleCustomize: null,
        packagingReflects: null,
        specialProcess: null,
        productionProcess: null,
        createTime: null,
        status: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
